package com.gitee.jjnnzb.designpatterninspring.business.openapi.handler.impl;

import com.gitee.jjnnzb.designpatterninspring.business.openapi.entity.bo.Source2Param;
import com.gitee.jjnnzb.designpatterninspring.business.openapi.handler.DataPushTemplate;
import com.gitee.jjnnzb.designpatterninspring.business.openapi.manager.MainTableInfoHandler;
import com.gitee.jjnnzb.designpatterninspring.common.enums.ChannelEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author Jjn
 * @since 2023/8/10 20:00
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class Channel2TemplateImpl extends DataPushTemplate {
    
    private final MainTableInfoHandler mainTableInfoHandler;
    
    @Override
    protected boolean checkIfAlreadyHandled(Map<String, Object> map) {
        Source2Param params = (Source2Param) map.get("params");
        String id = params.getId();
        if (log.isInfoEnabled()) {
            log.info("渠道2对应业务表查询ID:{}对应的数据", id);
        }
        return false;
    }
    
    @Override
    protected void handleBaseRecord(Map<String, Object> map) {
        mainTableInfoHandler.handleMainTable(map);
    }
    
    @Override
    protected void handleExtraInfo(Map<String, Object> map) {
        Long id = (Long) map.get("id");
        if (log.isInfoEnabled()) {
            log.info("处理渠道2对应的业务表信息，关联主表ID:{}", id);
        }
    }
    
    @Override
    protected String getChannelName() {
        return ChannelEnum.CHANNEL_TWO.getChannelName();
    }
}
